// GL && HF
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const ll inf = 1LL << 30LL;

int T, n, a[200010], c[200010];
bool b[200010];

inline ll calc() {
    ll sum = 0;
    int p0 = -1, p1 = -1;
    for (int i = 1; i <= n; i++)
        if (!b[i]) {
            if (p0 != -1 && a[i] == p0) c[i] = a[i];
            else c[i] = 0;
            p0 = a[i];
        } else {
            if (p1 != -1 && a[i] == p1) c[i] = a[i];
            else c[i] = 0;
            p1 = a[i];
        }
    for (int i = 1; i <= n; i++)
        sum += c[i];
    return sum;
}

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    scanf("%d", &T);
    for (; T--; ) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        ll ans = -inf;
        for (int i = 0; i < (1 << n); i++) {
            for (int t = i, cnt = n; t; t /= 2, --cnt)
                if (t & 1)
                    b[cnt] = true;
                else
                    b[cnt] = false;
            ans = max(ans, calc());
        }
        printf("%lld\n", ans);
    }
    return 0;
}
// O(2^n * n)
